package com.example.stars_project_android.personalCenter;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ListView;

import com.example.stars_project_android.R;
import com.example.stars_project_android.adapter.BlackUserListViewAdapter;
import com.example.stars_project_android.adapter.ConcernStarListAdapter;
import com.example.stars_project_android.entity.BlackUserEntity;
import com.example.stars_project_android.entity.ConcernStarEnetity;

import java.util.ArrayList;
import java.util.List;

/**
 * 黑名单界面
 */
public class BlackUser extends AppCompatActivity {

    private List<BlackUserEntity> lists = new ArrayList();
    private ListView listView;
    private BlackUserListViewAdapter adapter=null;
    private ImageView imageView;   //返回按钮


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_black_user);
        //绑定控件对象
        setView();
        //初始化lists，得到服务端的用户黑名单数据
        setData();
        //设置适配器
        SetBlackUserAdapter();
        //点击返回按钮
        imageView.setOnClickListener(view->{
            Intent intent = new Intent(BlackUser.this,SetUp.class);
            startActivity(intent);
        });
        //设置数据监听
        setListViewItemListner();
    }

    /**
     * 设置数据源
     */
    private void setData() {
        lists = new ArrayList<>();
        BlackUserEntity blackUser = new BlackUserEntity(R.mipmap.star,"HDK 4326-131-4","取消拉黑");
        BlackUserEntity blackUser1 = new BlackUserEntity(R.mipmap.star,"BDL 4726-134-1","取消拉黑");
        BlackUserEntity blackUser2 = new BlackUserEntity(R.mipmap.star,"LSM J2043-5610","取消拉黑");
        lists.add(blackUser);
        lists.add(blackUser1);
        lists.add(blackUser2);
    }

    private void setView() {
        listView = findViewById(R.id.list);
        imageView = findViewById(R.id.iv_black_back);
    }

    /**
     * listView的数据监听
     */
    private void setListViewItemListner() {
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                //点击取消黑名单，取消拉黑按钮改为拉黑，将此id从数据库中删除。
            }
        });
    }

    /**
     * listView绑定适配器
     */
    private void SetBlackUserAdapter() {
        adapter = new BlackUserListViewAdapter(this,R.layout.black_user_item,lists);//设置适配器
        listView.setAdapter(adapter);//ListView设置适配器
        //ListView item 中的删除按钮的点击事件
        adapter.setOnItemDeleteClickListener(new ConcernStarListAdapter.onItemDeleteListener() {
            @Override
            public void onDeleteClick(int i) {
                lists.remove(i);
                adapter.notifyDataSetChanged();
            }
        });
    }

}